package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.component.RoundCornerImageView;
import com.pdsu.graduation_design.domain.Agriculture;
import com.squareup.picasso.Picasso;

import java.util.List;

public class NewsAgricultureMessageAdapter extends BaseAdapter {


    /**
     * 待优化，数据从后台拿出  用List集合接受
     */

    //data

    private List<Agriculture> agricultures;

//    private int[] images={R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber,R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber};
//    private String[] titles={"potato","tomato","cucumber","potato","tomato","cucumber"};


    private Context context;
    private TextView textView,news_listview_item_time;
    private RoundCornerImageView roundCornerImageView;

    public NewsAgricultureMessageAdapter(List<Agriculture> agricultures, Context context) {
        this.agricultures = agricultures;
        this.context = context;
    }

    public NewsAgricultureMessageAdapter() {
    }



    @Override
    public int getCount() {
        return agricultures.size();
    }

    @Override
    public Object getItem(int position) {
        return agricultures.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view=View.inflate(context,R.layout.news_listview_item,null);


        textView=view.findViewById(R.id.news_listview_item_title);
        roundCornerImageView=view.findViewById(R.id.news_listview_item_image);
        news_listview_item_time=view.findViewById(R.id.news_listview_item_time);
/***
 *
 *
 * ...
 */
       // agricultures.add(new Agriculture(1,1,"@",R.drawable.potato,));

        textView.setText(agricultures.get(position).getTitle());
        news_listview_item_time.setText(agricultures.get(position).getTime());
        Picasso.with(context).load(agricultures.get(position).getImage()).into(roundCornerImageView);


        return view;
    }
}
